package cmd

import (
	"github.com/spf13/cobra"
	global2 "longmen/server/config/global"
	"longmen/server/internal/services/consumers/config"
	_const "longmen/server/pkg/common/helper/const"
	"longmen/server/pkg/common/lib/rabbitmq"
)

var txFansGroupInit = &cobra.Command{
	Use:   _const.PusherTxFansGroup,
	Short: "初始化粉丝群交换机 ",
	Long:  "初始化粉丝群交换机",
	Run: func(cmd *cobra.Command, args []string) {
		mq := rabbitmq.New(&config.RabbitConf, global2.Log)
		exchange, queue, options, consumerOptions := rabbitmq.GetRabbitConsumerConfig(global2.Config, global2.AppName)
		// 开启consumer
		_, err := mq.NewConsumer(exchange, queue, options, consumerOptions)
		if err != nil {
			global2.Log.Fatalf("new consumer[%s]: err : %v", global2.AppName, err)
		}

		//snowflake.SetStartTime(timehelper.Date(2021, 9, 1, 0, 0, 0, 0, timehelper.UTC))
		//snowflake.SetMachineID(1)
		//for {
		//	for i := 0; i < 100000; i++ {
		//		history := fans_group.FansGroupHistory{
		//			Seq:      int64(snowflake.ID()),
		//			Uid:      6011868,
		//			GroupId:  "6011859_800056",
		//			NickName: "测试昵称",
		//			Avatar:   "",
		//			Content:  "测试内容" + timehelper.Now().Format("2006-01-02 15:04:05"),
		//			SendTime: timehelper.Now().Unix(),
		//			Type:     0,
		//			Role:     0,
		//		}
		//		err := history.WriteToEsAndMQ(context.Background())
		//		if err != nil {
		//			global.Log.Error("发送消息失败: ", err)
		//		}
		//	}
		//	timehelper.Sleep(timehelper.Minute * 1)
		//}

	},
	PreRun: func(cmd *cobra.Command, args []string) {
		global2.AppName = _const.PusherTxFansGroup
		global2.Initialize(config.ConfigPath)
		config.InitConsumerConfig()
		err := global2.InitElasticSearch()
		if err != nil {
			global2.Log.Fatalf("init es: %v", err)
		}
	},
}
